#include <check.h>
#include "test_cover.h"

#include <signal.h>
#include <string.h>
#include "include/cover.h"

static cover_t cover; /* Compartida por los tests... */

static void teardown (void) {
	cover = cover_destroy (cover);
}

/* Testeo de precondiciones */
START_TEST (test_set_big_null)
{
	cover = cover_create (UNKNOWN);
	cover_set_big (cover, NULL);
}
END_TEST

START_TEST (test_set_thumb_null)
{
	cover = cover_create (UNKNOWN);
	cover_set_thumb (cover, NULL);
}
END_TEST

/* Testeo de funcionalidad */

START_TEST (test_set_big)
{
	char * url = "http://some.url.jpg";
	cover = cover_create (UNKNOWN);
	cover_set_big (cover, url);
	fail_unless (cover_get_big (cover) != url); /* Address compare */
	fail_unless (strncmp (cover_get_big (cover), url, sizeof (url)) == 0);
}
END_TEST

START_TEST (test_set_thumb)
{
	char * url = "http://some.url.jpg";
	cover = cover_create (UNKNOWN);
	cover_set_thumb (cover, url);
	fail_unless (cover_get_thumb (cover) != url); /* Address compare */
	fail_unless (strncmp (cover_get_thumb (cover), url, sizeof (url)) == 0);
}
END_TEST

START_TEST (test_cover_type)
{
	cover = cover_create (FRONT);
	fail_unless (cover_type (cover) == FRONT); /* Address compare */
}
END_TEST

/* Armado de la test suite */

Suite *cover_suite (void)
{
	Suite *s = suite_create ("cover");
	TCase *tc_preconditions = tcase_create ("Precondition");
	TCase *tc_functionality = tcase_create ("Functionality");

	/* Precondiciones */
	tcase_add_checked_fixture (tc_preconditions, NULL, teardown);
	tcase_add_test_raise_signal (tc_preconditions, test_set_big_null, SIGABRT);
	tcase_add_test_raise_signal (tc_preconditions, test_set_thumb_null, SIGABRT);
	suite_add_tcase (s, tc_preconditions);

	/* Funcionalidad */
	tcase_add_checked_fixture (tc_functionality, NULL, teardown);
	tcase_add_test (tc_functionality, test_set_big);
	tcase_add_test (tc_functionality, test_set_thumb);
	tcase_add_test (tc_functionality, test_cover_type);
	
	suite_add_tcase (s, tc_functionality);

	return s;
}

